package com.immunology.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.AttributeContent;
import com.immunology.model.MappingPages;
import com.immunology.model.User;
import com.immunology.service.UserService;

public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public UserServlet() {

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		User userFromSession = (User) request.getSession().getAttribute(
				AttributeContent.USER);
		UserService userService = new UserService();
		if (userFromSession != null) {
			String stringId = request.getParameter("id");
			int id = Integer.parseInt(stringId);
			User user = userService.getUserById(id);
			request.setAttribute("userFromSession", userFromSession);
			request.setAttribute("user", user);
			getServletContext().getRequestDispatcher(MappingPages.DOCTOR_JSP)
					.forward(request, response);
		} else {
			response.sendRedirect("");
		}

	}

}